﻿using AutoMapper;
using MediatR;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.Supplier;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Set.API.Application.Commands.Supplier
{
    /// <summary>
    /// 银行信息删除
    /// </summary>
    public class BanksDeleteHandler : IRequestHandler<BanksDeleteCommand, THE_WIND_RISES.Common.Dtos.Result>
    {
        /// <summary>
        /// 银行信息
        /// </summary>
        private readonly IBaseRepository<Banks> banksRepository;
        /// <summary>
        /// 映射
        /// </summary>
        private readonly IMapper mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="banksRepository"></param>
        public BanksDeleteHandler(IBaseRepository<Banks> banksRepository)
        {
            this.banksRepository = banksRepository;
        }
        public async Task<Result> Handle(BanksDeleteCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Delete };

            try
            {
                string sql = $"update Banks set IsDelete=1 where BanksId={request.BanksId}";

                var list = banksRepository.Update(sql, result);

                if (list > 0)
                {
                    result.Code = (int)CommonErrorCodes.Success;
                    result.Msg = "删除成功";
                }
            }
            catch (Exception)
            {

                throw;
            }

            return result;
        }
    }
}
